<?php
/**
 * 用户控制系统
 *
 * 系统入口点
 */
include './config/config.inc.php';
include './uc_client/client.php';
include './include/db.php';
/**
 * 获取当前用户的 UID 和 用户名
 * Cookie 解密直接用 uc_authcode 函数，用户使用自己的函数
 */
if (! empty($_COOKIE['HAGT_auth']))
{
    list ($HAGT_uid, $HAGT_username) = explode("\t", 
    uc_authcode($_COOKIE['HAGT_auth'], 'DECODE'));
} else
{
    $HAGT_uid = $HAGT_username = '';
}

/**
 * 显示用户控制栏
 */
if (! $HAGT_username)
{
    //用户未登录
    echo '<a href="' . $_SERVER['PHP_SELF'] . '?action=login">登录</a> ';
    echo '<a href="' . $_SERVER['PHP_SELF'] . '?action=register">注册</a> ';
    echo '<a href="index.php">首页</a> ';
} else
{
    //用户已登录
    echo "<div id='page_set'><span>$HAGT_username </span>";
    echo ' <a href="' . $_SERVER['PHP_SELF'] . '?action=avatar">头像</a> ';
    echo ' <a href="' . $_SERVER['PHP_SELF'] . '?action=logout">退出</a> ';
    echo '<a href="index.php">首页</a> ';
}

echo '<hr />';

/**
 * 解析分析各action
 */
switch (@$_GET['action'])
{
    case 'login':
        //用户登录
        include 'lib/user/login.php';
        break;
    case 'logout':
        //UCenter 用户退出
        include 'lib/user/logout.php';
        break;
    case 'register':
        //UCenter 用户注册
        include 'lib/user/register.php';
        break;
    case 'avatar':
        //UCenter 设置头像
        include 'lib/user/avatar.php';
        break;
}
?>
</body>
</html>

